%reading the data file
clc
DataFile = csvread('sc4002e0-rec_data.txt',1,0);
%DataFile
Time = DataFile(:,1);
EEG1 = DataFile(:,2);
%EEG1
EEG2 = DataFile(:,3);
WindowSizeFrequency = 1;
WindowSizeAmplitude = 1;
Interval = 0.01;
SpindleFreqRangeLow = 12;
SpindleFreqRangeHigh = 14;
SpindleMinimumThresholdTime = 0.5;
SpindleIntervalThreshold = 3;
n = length(Time);
for i = 1 : n
    if length(EEG1) >= i + WindowSizeFrequency/Interval;
        [Frequency(i)] = DetermineFrequencyInEpoch(EEG1, WindowSizeFrequency, Interval, i);       
        fprintf('Frequency in Interval %f - %f sec = %f\n', i*Interval, (i-1)*Interval + WindowSizeFrequency, Frequency);
    end
    if length(EEG1) >= i + WindowSizeAmplitude/Interval;
        [AvgAmplitude(i)] = CalculateAverageAmplitude(EEG1, WindowSizeAmplitude, Interval, i);
        fprintf('Avg Amplitude in Interval %f - %f sec = %f\n', i*Interval, (i-1)*Interval + WindowSizeAmplitude, AvgAmplitude);
    end
    fprintf('\n');
end
[SleepSpindle] = CheckIfSleepSpindle(Frequency, WindowSizeFrequency, SpindleFreqRangeLow, SpindleFreqRangeHigh, SpindleMinimumThresholdTime);
[StageClassificationOnSpindle] = ClassifyBasedOnSpindle(SleepSpindle, SpindleIntervalThreshold);

